package com.xpu.cos.controller;



import com.xpu.cos.entity.Orders;
import com.xpu.cos.result.Result;
import com.xpu.cos.service.OrderService;
import com.xpu.cos.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ambitionjh
 * @since 2024-01-02
 */
@RestController
@RequestMapping("/cos/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    //添加订单
    @PostMapping("add")
    public Result addOrder(@RequestBody Orders order){
        return orderService.addOrder(order);
    }

    //取消订单
    @DeleteMapping("cancel/{goodsId}")
    public Result deleteOrder(@PathVariable Integer goodsId){
        return orderService.deleteOrder(goodsId);
    }

    //查询用户所有订单
    @GetMapping("allOrder")
    public Result getAllOrder(){
        int userId = Integer.parseInt(TokenUtils.getUserId());
        return orderService.getAllOrder(userId);
    }

}

